﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace B2B.Models
{
    public class SP_ChiTietSanPham
    {
        int maSP;

        public int MaSP
        {
            get { return maSP; }
            set { maSP = value; }
        }
        string tenSP;

        public string TenSP
        {
            get { return tenSP; }
            set { tenSP = value; }
        }
        string hinhAnh;

        public string HinhAnh
        {
            get { return hinhAnh; }
            set { hinhAnh = value; }
        }
        double donGia;

        public double DonGia
        {
            get { return donGia; }
            set { donGia = value; }
        }
        int soLuongDatToiThieu;

        public int SoLuongDatToiThieu
        {
            get { return soLuongDatToiThieu; }
            set { soLuongDatToiThieu = value; }
        }
        int khaNangCungUng;

        public int KhaNangCungUng
        {
            get { return khaNangCungUng; }
            set { khaNangCungUng = value; }
        }
        string maLoaiThanhToan;

        public string MaLoaiThanhToan
        {
            get { return maLoaiThanhToan; }
            set { maLoaiThanhToan = value; }
        }
        int maTV;

        public int MaTV
        {
            get { return maTV; }
            set { maTV = value; }
        }
        string hoTen;

        public string HoTen
        {
            get { return hoTen; }
            set { hoTen = value; }
        }
        string chitiet;

        public string Chitiet
        {
            get { return chitiet; }
            set { chitiet = value; }
        }

        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        public SP_ChiTietSanPham chiTietSanPham(int maSP)
        {
            SP_ChiTietSanPham chitietSP = new SP_ChiTietSanPham();

            SqlConnection conn = KetNoi.Connection();
            SqlCommand cmd = new SqlCommand("sp_ChiTietSanPham", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@maSP", maSP);
            conn.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                chitietSP.MaSP = reader.GetInt32(0);
                chitietSP.tenSP = reader.GetString(1);
                chitietSP.HinhAnh = reader.GetString(2);
                chitietSP.DonGia = double.Parse(reader.GetDecimal(3).ToString());
                chitietSP.SoLuongDatToiThieu = reader.GetInt32(4);
                chitietSP.KhaNangCungUng = reader.GetInt32(5);
                chitietSP.MaLoaiThanhToan = reader.GetString(6);
                chitietSP.MaTV = reader.GetInt32(7);
                chitietSP.HoTen = reader.GetString(8);

                if (reader.GetString(9) == null)
                    chitietSP.Chitiet = "";
                else
                    chitietSP.Chitiet = reader.GetString(9);
                chitietSP.Email = reader.GetString(10);
            }
            conn.Close();


            return chitietSP;
        }
      
    }
}